package com.ruoyi.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.lang.StringUtils;

public class DateUtil {

	/**
	 * 获取当前日期
	 * 
	 * @param n
	 * @return
	 */
	public static Date now() {
		Calendar c = new GregorianCalendar();
		return c.getTime();
	}

	public static Date today() {
		return fixDate(now());
	}
	
	  /**
     * 计算得到MongoDB存储的日期，（默认情况下mongo中存储的是标准的时间，中国时间是东八区，存在mongo中少8小时，所以增加8小时）
     * http://www.iteye.com/problems/88507
     * 
     * @author: Gao Peng
     * @date: 2016年5月4日 上午9:26:23
     * @param: @param
     *             date
     * @param: @return
     * @return: Date
     */
    public static Date getMongoDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        ca.add(Calendar.HOUR_OF_DAY, 8);
        return parseDate(sdf.format(ca.getTime()));
    }

	/**
	 * 获取当前日期
	 * 
	 * @param n
	 * @return
	 */
	public static String now(String format) {
		SimpleDateFormat fmt = new SimpleDateFormat(format);
		Calendar c = new GregorianCalendar();
		return fmt.format(c.getTime());
	}

	/**
	 * 获取当前日期前N天
	 * 
	 * @param n
	 * @return
	 */
	public static Date preDay(int n) {
		Calendar c = new GregorianCalendar();
		int day = c.get(Calendar.DAY_OF_YEAR);
		c.set(Calendar.DAY_OF_YEAR, (day - n));
		return c.getTime();
	}

	public static Date preDays(Date date, int preDays) {
		GregorianCalendar c1 = new GregorianCalendar();
		c1.setTime(date);
		GregorianCalendar cloneCalendar = (GregorianCalendar) c1.clone();
		cloneCalendar.add(Calendar.DATE, -preDays);
		return cloneCalendar.getTime();
	}

	/**
	 * 获取当前日期之后N天
	 * 
	 * @param n
	 * @return
	 */
	public static Date nextDay(int n) {
		Calendar c = new GregorianCalendar();
		int day = c.get(Calendar.DAY_OF_YEAR);
		c.set(Calendar.DAY_OF_YEAR, (day + n));
		return c.getTime();
	}

	public static Date nextDays(Date date, int nextDays) {
		GregorianCalendar c1 = new GregorianCalendar();
		c1.setTime(date);
		GregorianCalendar cloneCalendar = (GregorianCalendar) c1.clone();
		cloneCalendar.add(Calendar.DATE, nextDays);
		return cloneCalendar.getTime();
	}

	public static Date preMonth(int n) {
		Calendar c = new GregorianCalendar();
		int month = c.get(Calendar.MONTH);
		c.set(Calendar.MONTH, (month - n));
		return c.getTime();
	}

	public static Date preMonth(int n, Date date) {
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		int month = c.get(Calendar.MONTH);
		c.set(Calendar.MONTH, (month - n));
		return c.getTime();
	}

	public static Date nextMonth(int n, Date date) {
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		int month = c.get(Calendar.MONTH);
		c.set(Calendar.MONTH, (month + n));
		return c.getTime();
	}

	public static int get(int field) {
		Calendar c = new GregorianCalendar();
		return c.get(field);
	}

	public static int get(Date date, int field) {
		GregorianCalendar c = new GregorianCalendar();
		c.setTime(date);
		return c.get(field);
	}

	public static long getMillis() {
		GregorianCalendar c = new GregorianCalendar();
		return c.getTimeInMillis();
	}

	/**
	 * 时间转换，默认:yyyy-MM-dd HH:mm:ss
	 * 
	 * @param date
	 * @return
	 */
	public static Date parseDate(String date) {
		return parseDate(date, "yyyy-MM-dd HH:mm:ss");
	}

	public static Date parseDay(String date) {
		return parseDate(date, "yyyy-MM-dd");
	}

	public static Date toDate(long updateTime) {
		Calendar c1 = new GregorianCalendar();
		c1.setTimeInMillis(updateTime);
		return c1.getTime();
	}

	/**
	 * 字符串转换成日期.
	 * 
	 * @param date
	 *            日期字符
	 * @param pattern
	 *            格式化.
	 * @return
	 */
	public static Date parseDate(String date, String pattern) {

		if (StringUtils.isBlank(pattern)) {
			pattern = "yyyy-MM-dd HH:mm:ss";
		}

		SimpleDateFormat fmt = new SimpleDateFormat(pattern);

		try {

			return fmt.parse(date);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		return null;

	}

	/**
	 * 获取昨天的时间.
	 * 
	 * @return
	 */
	public static Date getYestoday() {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(new Date());// 设置当前时间
		calendar.add(Calendar.DATE, -1);
		return calendar.getTime();
	}

	/**
	 * 获取上一个小时的时间.
	 * 
	 * @return
	 */
	public static Date getLastHour() {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(new Date());// 设置当前时间
		calendar.add(Calendar.HOUR, -1);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return calendar.getTime();
	}

	public static Date getPreHour(int n) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(new Date());// 设置当前时间
		calendar.add(Calendar.HOUR, -n);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return calendar.getTime();
	}
	
	public static Date getThisHour() {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(new Date());// 设置当前时间
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return calendar.getTime();
	}

	/**
	 * 获取当前时间是星期几.
	 * 
	 * @param date
	 * @return
	 */
	public static int getDayOfWeek(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		return calendar.get(Calendar.DAY_OF_WEEK);
	}

	/**
	 * 判断是否每月的第一天.
	 * 
	 * @param date
	 * @return
	 */
	public static boolean isFirstDayOfMonth(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		return day == 1;
	}

	public static Date getFirstDayOfWeek() {
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.DAY_OF_WEEK, 2);
		return calendar.getTime();
	}

	public static Date getFirstDayOfWeek(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		int dayofweek = calendar.get(Calendar.DAY_OF_WEEK);
		if (dayofweek == 1) { // 如果当前日期是周末的话, 把时间往前一天, 因为在Java里面每周的第一天是周末
			calendar.setTime(preDays(date, 1));
		}
		calendar.set(Calendar.DAY_OF_WEEK, 2);
		return calendar.getTime();
	}

	public static Date getFirstDayPreWeek(int n) {
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.WEEK_OF_YEAR, calendar.get(Calendar.WEEK_OF_YEAR)
				- n);
		int dayofweek = calendar.get(Calendar.DAY_OF_WEEK);
		if (dayofweek == 1) { // 如果当前日期是周末的话, 把时间往前一天, 因为在Java里面每周的第一天是周末
			calendar.setTime(preDay(1));
		}
		calendar.set(Calendar.DAY_OF_WEEK, 2);
		return calendar.getTime();
	}

	public static Date getFirstDayPresWeek(Date date, int n) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		calendar.set(Calendar.WEEK_OF_YEAR, calendar.get(Calendar.WEEK_OF_YEAR)
				- n);
		int dayofweek = calendar.get(Calendar.DAY_OF_WEEK);
		if (dayofweek == 1) { // 如果当前日期是周末的话, 把时间往前一天, 因为在Java里面每周的第一天是周末
			calendar.setTime(preDays(date, 1));
		}
		calendar.set(Calendar.DAY_OF_WEEK, 2);
		return calendar.getTime();
	}

	public static Date getLastDayPreWeek(int n) {
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.WEEK_OF_YEAR, calendar.get(Calendar.WEEK_OF_YEAR)
				- n + 1);
		int dayofweek = calendar.get(Calendar.DAY_OF_WEEK);
		if (dayofweek == 1) { // 如果当前日期是周末的话, 把时间往前一天, 因为在Java里面每周的第一天是周末
			calendar.setTime(preDay(1));
		}
		calendar.set(Calendar.DAY_OF_WEEK, 1);
		return calendar.getTime();
	}

	/**
	 * 获取当月的第一天
	 * 
	 * @param date
	 * @return
	 */
	public static Date getFirstDayOfMonth() {
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getFirstDayOfMonth(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getFirstDayOfMonth(Date date, int pre) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		int month = calendar.get(Calendar.MONTH);
		calendar.set(Calendar.MONTH, (month - pre));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getFirstDayOfLastMonth() {
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.MONTH, (calendar.get(Calendar.MONTH) - 1));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getFirstDayOfLastMonth(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.set(Calendar.MONTH, (calendar.get(Calendar.MONTH) - 1));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getLastDayOfLastMonth() {
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.MONTH, (calendar.get(Calendar.MONTH) - 1));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getLastDayOfLastMonth(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.set(Calendar.MONTH, (calendar.get(Calendar.MONTH) - 1));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getHalfDayOfLastMonth(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.set(Calendar.MONTH, (calendar.get(Calendar.MONTH) - 1));
		calendar.set(Calendar.DAY_OF_MONTH, 15);
		return calendar.getTime();
	}

	public static Date getHalfDayOfLastMonth() {
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.MONTH, (calendar.get(Calendar.MONTH) - 1));
		calendar.set(Calendar.DAY_OF_MONTH, 15);
		return calendar.getTime();
	}

	public static Date getLastDayOfMonth(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	public static Date getLastDayOfMonth(Date date, int pre) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		int month = calendar.get(Calendar.MONTH);
		calendar.set(Calendar.MONTH, (month - pre));
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}

	/**
	 * 获取某个时间点的上一个小时
	 * 
	 * @param date
	 * @return
	 */
	public static Date getLastHour(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);// 设置当前时间
		calendar.add(Calendar.HOUR, -1);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return calendar.getTime();
	}

	/**
	 * 获取7天前的时间
	 * 
	 * @return
	 */
	public static Date getLastTday() {
		Calendar calendar = new GregorianCalendar();
		calendar.add(Calendar.DATE, -7);
		return calendar.getTime();
	}

	/**
	 * 获取7天前的时间
	 * 
	 * @return
	 */
	public static Date getLastNMonth(int month) {
		Calendar calendar = new GregorianCalendar();
		calendar.add(Calendar.MONTH, month);
		return calendar.getTime();
	}

	/**
	 * 获取N天前或N天后的时间
	 * 
	 * @param n
	 *            正数表示N天后，负数表示N天前
	 * @return
	 */
	public static Date getLastNday(int n) {
		Calendar calendar = new GregorianCalendar();
		calendar.add(Calendar.DATE, n);
		return calendar.getTime();
	}

	/**
	 * 获取本月头一天的日期.
	 * 
	 * @return
	 */
	public static Date getStartDateOfCurrentMonth() {

		Calendar calendar = new GregorianCalendar();
		int startDay = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);// 开始日期
		calendar.set(Calendar.DAY_OF_MONTH, startDay);
		return calendar.getTime();
	}

	/**
	 * 获取昨天的时间.
	 * 
	 * @return
	 */
	public static String getYestoday(String formatter) {
		SimpleDateFormat fmt = new SimpleDateFormat(formatter);
		String date = fmt.format(getYestoday());
		return date;
	}

	/**
	 * 格式时间.
	 * 
	 * @return
	 */
	public static String format(Date date, String formatter) {
		SimpleDateFormat fmt = new SimpleDateFormat(formatter);
		return fmt.format(date);
	}

	public static String formatDay(Date date) {
		SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		return fmt.format(date);
	}

	public static String formatTime(Date date) {
		SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return fmt.format(date);
	}

	/**
	 * 判断某个时间是否为一周的第一天
	 * 
	 * @param date
	 * @return
	 */
	public static boolean isFirstDayOfWeek(Date date) {

		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);

		int i = calendar.get(Calendar.DAY_OF_WEEK);

		// 周日作为一周的开始
		if (i == Calendar.SATURDAY) {
			return true;
		}

		return false;
	}

	/**
	 * 判断某个时间是否为一周的第一天
	 * 
	 * @param date
	 * @return
	 */
	public static int getHourOfDay(Date date) {

		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		return calendar.get(Calendar.HOUR_OF_DAY);
	}

	/**
	 * 比较两个 Date 对象表示的时间值（从历元至现在的毫秒偏移量）。
	 * 
	 * @param d1
	 * @param d2
	 * @return 如果 d1 表示的时间等于 d2 表示的时间，则返回 0 值；如果此 d1 的时间在d2表示的时间之前，则返回小于 0 的值；如果
	 *         d1 的时间在 d2 表示的时间之后，则返回大于 0 的值。
	 * 
	 */
	public static int compareDateTime(Date d1, Date d2) {

		Calendar c1 = new GregorianCalendar();
		Calendar c2 = new GregorianCalendar();
		c1.setTime(d1);
		c2.setTime(d2);

		return c1.compareTo(c2);
	}

	/**
	 * 比较两个 Date 对象表示的日期值（仅仅比较日期,忽略时分秒）。 -wuwm
	 * 
	 * @param d1
	 * @param d2
	 * @return 如果 d1 表示的日期等于 d2 表示的日期，则返回 0 值；如果此 d1 的日期在d2表示的日期之前，则返回小于 0 的值；如果
	 *         d1 的日期在 d2 表示的日期之后，则返回大于 0 的值。
	 * 
	 */
	public static int compareDate(Date d1, Date d2) {

		d1 = DateUtil
				.parseDate(DateUtil.format(d1, "yyyy-MM-dd"), "yyyy-MM-dd");
		d2 = DateUtil
				.parseDate(DateUtil.format(d2, "yyyy-MM-dd"), "yyyy-MM-dd");
		Calendar c1 = new GregorianCalendar();
		Calendar c2 = new GregorianCalendar();
		c1.setTime(d1);
		c2.setTime(d2);

		return c1.compareTo(c2);
	}

	/**
	 * 比较两个 Date 对象表示的月份值（仅仅比较月份,忽略日时分秒）。 -wuwm
	 * 
	 * @param d1
	 * @param d2
	 * @return 如果 d1 表示的日期等于 d2 表示的日期，则返回 0 值；如果此 d1 的日期在d2表示的日期之前，则返回小于 0 的值；如果
	 *         d1 的日期在 d2 表示的日期之后，则返回大于 0 的值。
	 * 
	 */
	public static int compareMonth(Date d1, Date d2) {

		d1 = DateUtil.parseDate(DateUtil.format(d1, "yyyy-MM"), "yyyy-MM");
		d2 = DateUtil.parseDate(DateUtil.format(d2, "yyyy-MM"), "yyyy-MM");
		Calendar c1 = new GregorianCalendar();
		Calendar c2 = new GregorianCalendar();
		c1.setTime(d1);
		c2.setTime(d2);

		return c1.compareTo(c2);
	}

	/**
	 * 计算时间差 d2 - d1
	 * 
	 * @param d1
	 * @param d2
	 * @return
	 */
	public static long difftime(Date d1, Date d2) {
		Calendar c1 = new GregorianCalendar();
		Calendar c2 = new GregorianCalendar();
		c1.setTime(d1);
		c2.setTime(d2);
		return c2.getTimeInMillis() - c1.getTimeInMillis();
	}

	public static long diffDay(Date d1, Date d2) {
		Calendar c1 = new GregorianCalendar();
		Calendar c2 = new GregorianCalendar();
		c1.setTime(d1);
		c2.setTime(d2);
		c1.set(Calendar.HOUR_OF_DAY, 0);
		c2.set(Calendar.HOUR_OF_DAY, 0);
		c1.set(Calendar.MINUTE, 0);
		c2.set(Calendar.MINUTE, 0);
		c1.set(Calendar.SECOND, 0);
		c2.set(Calendar.SECOND, 0);
		c1.set(Calendar.MILLISECOND, 0);
		c2.set(Calendar.MILLISECOND, 0);
		// return c2.compareTo(c1);
		return (c2.getTimeInMillis() - c1.getTimeInMillis())
				/ (1000 * 60 * 60 * 24);
	}

	public static String getYearMonth() {
		Calendar c = new GregorianCalendar();
		int month = c.get(Calendar.MONTH);
		month++;
		if (month < 10) {
			return c.get(Calendar.YEAR) + "-0" + month;
		} else {
			return c.get(Calendar.YEAR) + "-" + month;
		}
	}

	// public static long diffMonth(Date d1, Date d2) {
	// Calendar c1 = new GregorianCalendar();
	// Calendar c2 = new GregorianCalendar();
	// c1.setTime(d1);
	// c1.set(Calendar.DAY_OF_MONTH, 1);
	// c1.set(Calendar.MILLISECOND, 0);
	//
	// c2.setTime(d2);
	// c2.set(Calendar.DAY_OF_MONTH, 1);
	// c2.set(Calendar.MILLISECOND, 0);
	// return (c2.getTimeInMillis() - c1.getTimeInMillis()) / (1000 * 60 * 60
	// *24);
	// }

	// 取得日期时间为一年中的第几周
	public static int getWeekOfYear(Date date) {
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		return c.get(Calendar.WEEK_OF_YEAR);
	}

	public static int getDayOfMonth(Date date) {
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		return c.get(Calendar.DAY_OF_MONTH);
	}

	/**
	 * java默认以周日为每周的第一天. 所以这里要获得向后的周日. 需要的是下一周的周日.
	 * */
	public static Date getLastDayOfWeek(Date date) {
		Calendar c = new GregorianCalendar();
		c.setTime(nextDays(date, 7));
		c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		return c.getTime();
	}

	public static Date preHour(int n) {
		Calendar c = new GregorianCalendar();
		int hour = c.get(Calendar.HOUR_OF_DAY);
		c.set(Calendar.HOUR_OF_DAY, hour - n);
		return c.getTime();
	}
	
	
	public static Date addHour(int n) {
		Calendar c = new GregorianCalendar();
		c.add(Calendar.HOUR_OF_DAY, n);
		return c.getTime();
	}
	

	public static Date preHour(Date date, int n) {
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		int hour = c.get(Calendar.HOUR_OF_DAY);
		c.set(Calendar.HOUR_OF_DAY, hour - n);
		return c.getTime();
	}

	public static Date plusHour(Date date, int n) {
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		int hour = c.get(Calendar.HOUR_OF_DAY);
		c.set(Calendar.HOUR_OF_DAY, hour + n);
		return c.getTime();
	}

	/**
	 * 通过将Date格式化为String 在转换为Date. 来去掉多余的数据.
	 * */
	public static Date fixDate(Date date, String pattern) {
		String temp = format(date, pattern);
		Date d = parseDate(temp, pattern);
		return d;
	}

	public static Date fixDate(Date date) {
		String pattern = "yyyy-MM-dd";
		String temp = format(date, pattern);
		Date d = parseDate(temp, pattern);
		return d;
	}

	public static Date addTimes(Date startTime, long times) {
		Calendar c = new GregorianCalendar();
		c.setTime(startTime);
		c.add(Calendar.SECOND, (int) times);
		return c.getTime();
	}
	
	public static Date getTodayStartTime(){
		Calendar c = new GregorianCalendar();
		c.setTime(new Date());
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		return c.getTime();
	}
	
	
	public static Date getTodayEndTime(){
		Calendar c = new GregorianCalendar();
		c.setTime(new Date());
		c.set(Calendar.HOUR_OF_DAY, 23);
		c.set(Calendar.MINUTE, 59);
		c.set(Calendar.SECOND, 59);
		return c.getTime();
	}

	
	/**
	 * 获取当天的周号
	 * @return
	 */
	public static int getCurrentWeekNo(){
		Calendar c = new GregorianCalendar();
//		c.setTime(new Date());
		return c.get(Calendar.WEEK_OF_YEAR);
	}
	
	
	/**
	 * 获取当天的周号
	 * @return
	 */
	public static Date getCurrentWeekStartTime(){
		Calendar c = new GregorianCalendar();
		c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
		return c.getTime();
	}
	
	
	
	/**
	 * 获取当天的周号
	 * @return
	 */
	public static Date getWeekStartTime(Date date){
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
		return c.getTime();
	}
	
	/**
	 * 获取当天的周号
	 * @return
	 */
	public static Date getWeekEndTime(Date date){
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		c.set(Calendar.DAY_OF_WEEK, c.getMaximum(Calendar.DAY_OF_WEEK));
		return c.getTime();
	}
	
	/**
	 * 获取几天前/几天后的日期
	 * @param n
	 * @return
	 */
	public static String getToday(int difnum) {
		// TODO Auto-generated method stub
		java.util.Date myDate = new java.util.Date();
		long myTime = (myDate.getTime() / 1000) + (difnum * 60 * 24 * 365);
		myDate = new java.util.Date();
		java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(
				"yyyy-MM-dd");
		String mDate = formatter.format(myDate);
		myTime = (myDate.getTime() / 1000) + (difnum * 60 * 60 * 24);
		myDate.setTime(myTime * 1000);
		mDate = formatter.format(myDate);
		return mDate;
	}
	
	/**
	 * 多少分钟前/后的时间 
	 * @param minute  如果是2分钟前  这里的值为2   如果是2分钟后 为-2
	 * @return 计算过后的时间
	 */
	public static Date parseMinute(int minute) {
		
		long time = minute*60*1000;
		Date now = new Date();
		Date date = new Date(now .getTime() - time);
		return date;
	}
	
	public static void main(String[] args) throws InterruptedException {
		
//		long d = DateUtil.compareDateTime(new Date(), DateUtil.parseDate("2015-09-30 12:10:00"));
//		System.out.println(d);
		
		System.out.println(getCurrentWeekNo());
	}
}
